<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use lib\Image;
use lib\Curl;
class Demo extends Controller{
	public function a($lng,$lat){
		$field='*,(power(mod(abs(lng - '.$lng.'),360),2) + power(abs(lat - '.$lat.'),2)) * 1000000 AS distance';
		$rel=Db::name('demo')
    	->field($field)
    	->order('distance asc')
    	->select();
    	show($rel);
    	$rel2=$rel;
    	array_walk($rel2,function(&$item) use($lng,$lat){
    		$item['distance2']=getDistance($item['lng'],$item['lat'],$lng,$lat,1);
    	});
    	show($rel2);
//		SELECT locationId,lon,lat,(power(mod(abs(lon - x),360),2) + power(abs(lat - y),2)) AS distance FROM `eyanghu_location`
//        ORDER BY distance LIMIT 1000
//		$rel=Db::name('member')
//		->field('id,,nickname')
//		->where(['id'=>['between',[3,10]]])
//		->select();
//		show($rel);
	}
	public function b(){
		$rel=Db::name('system_admin')->select();
		show($rel);
		echo rand(1,3);
//		$data=[
//			'name' => 'admin',
//			'password'=>'admin'
//		];
//		
//		$rel=Curl::http_curl();
//		$rel=db('users')->select();
//		show($rel);
	}
	public function c($type){
		$user=Db::name('users')->where('uid',1)->find();
		$insert=['uid'=>1,'linkid'=>0,'type'=>$type,'ctime'=>time()];
		$score_config=config('base.score');
		
		if(isset($score_config[$type])){
			$insert['score']=$score_config[$type]['score'];
			$insert['remark']=$score_config[$type]['remark'];
		}else{
			$insert['score']=$score;
			$insert['remark']=$remark;
		}
		$msg=[
			'touser'	=>$user['openid'],
			'template_id'=>'KYvktEFlJcNfcUnDhWVc4kE08fZpwK1MghTL52YmAQc',
			'url'		=>'http://www.fanshangxi.cn/web/user/score',
			'data'      =>[
				'first'=>['value'=>'积分变更通知','color'=>'#173177'],
				'keyword1'=>['value'=>$insert['score'],'color'=>'#173177'],
				'keyword2'=>['value'=>$insert['remark'],'color'=>'#173177'],
				'keyword3'=>['value'=>date('Y-m-d H:i:s',time()),'color'=>'#173177'],
				'keyword4'=>['value'=>$user['score'],'color'=>'#173177'],
				'remark'=>['value'=>'如有疑问请致电：13627233877','color'=>'#173177']
			],
		];
		show($msg);
		show(json_encode($msg));
	}
}
